﻿using BusinessBingo.Common.Interfaces;
using BusinessBingo.Data;
using BusinessBingo.Data.Interfaces;
using Castle.Core;
using Castle.MicroKernel.Registration;
using Castle.MicroKernel.SubSystems.Configuration;
using Castle.Windsor;

namespace BusinessBingo.Installer
{
    /// <summary>
    /// WindsorInstaller for Data project
    /// </summary>
    public class DataInstaller : IWindsorInstaller
    {
        private LifestyleType _lifestyleType;

        public DataInstaller(LifestyleType lifestyleType)
        {
            this._lifestyleType = lifestyleType;
        }

        /// <summary>
        /// Register Data componentes in container
        /// </summary>
        /// <param name="container">IoC Container where compontents are registered</param>
        /// <param name="store">IoC Store for configuration </param>
        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            container.Register(
                Component.For<IUnitOfWork>().ImplementedBy<BusinessBingoDBEntities>().LifeStyle.Is(
                    this._lifestyleType));
            container.Register(
                Component.For<IBingoSetRepository>().ImplementedBy<EFBingoSetRepository>().LifeStyle.Is(
                    this._lifestyleType));
            container.Register(
                Component.For<IGroupRepository>().ImplementedBy<EFGroupRepository>().LifeStyle.Is(
                    this._lifestyleType));
            container.Register(
                Component.For<IGameRepository>().ImplementedBy<EFGameRepository>().LifeStyle.Is(
                    this._lifestyleType));
            container.Register(
                Component.For<IUserRepository>().ImplementedBy<EFUserRepository>().LifeStyle.Is(
                    this._lifestyleType));
            container.Register(
                Component.For<IWordRepository>().ImplementedBy<EFWordRepository>().LifeStyle.Is(
                    this._lifestyleType));
        }
    }
}
